package com.my.study;

import org.apache.commons.collections4.CollectionUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

public class MyTest {

    public static void main(String[] args) throws ParseException {

        String a = "abcd";
//        System.out.println(isIllegalTrackingNumber("123456FX花儿一样"));
//
//        System.out.println(isIllegalTrackingNumber("12333"));
//
//        System.out.println(isIllegalTrackingNumber("aaaaaa"));
//
//        System.out.println(isIllegalTrackingNumber("   a12344554*"));


        //List<Integer> res = Arrays.asList(null);
        List<Integer> res = new ArrayList<>();
        System.out.println(res);
        res.add(null);
        System.out.println(CollectionUtils.isEmpty(res));

//        System.out.println("======" + a.substring(0,0));
//
//        double res = OperationEnum.PLUS.apply(2.0, 3.0);
//        System.out.println("=====" + res);
//
//        System.out.println(getDateTimeRange(new Date()));
//        System.out.println(getOffSetTime(-1));
//
//        int zlx = 1;
//        char tmp = (char) (zlx + '0');
//        System.out.println("tmp value is ======" + tmp);
//
//        List<String> dts = new ArrayList<>();
//
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Date selectedTime = sdf.parse("2019-07-19");
//        Calendar cal = Calendar.getInstance();
//        cal.setTime(selectedTime);
//        Date preYesterday = sdf.parse(getOffSetTime(-1));
//        while (cal.getTimeInMillis() < preYesterday.getTime()) {
//            String dt = sdf.format(cal.getTime());
//            dts.add(dt);
//            cal.add(Calendar.DAY_OF_MONTH, 1);
//        }
//        for(String dt : dts){
//            System.out.println(dt);
//        }


    }


    public static boolean isIllegalTrackingNumber(String trackingNumber){

        Pattern pattern = Pattern.compile("^[A-Za-z0-9]*[0-9]+[A-Za-z0-9]*$");
        if(pattern.matcher(trackingNumber).find()){
            return true;
        }
        return false;
    }

    /**
     * 获取前offset天的字符串
     * @param offset
     * @return
     */
    public static String getOffSetTime(Integer offset){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, offset);
        String offsetDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        return offsetDate;
    }


    /**
     * 获取从当天 0：00：00-23：59：59
     * @param day
     * @return
     */
    public static Map<Integer, Date> getDateTimeRange(Date day) {
        //获取当天开始结束时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(day);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        Date startDate = calendar.getTime();

        calendar.add(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.SECOND, -1);

        Date endDate = calendar.getTime();

        Map<Integer, Date> result = new HashMap<Integer, Date>();
        result.put(0, startDate);
        result.put(1, endDate);
        return result;
    }

}
